package org.alanlau.ribbon.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * ribbon api的使用
 *
 * @author alan
 * @version 1.0
 * @date 2020/9/13 19:42
 */
@RestController
@RequestMapping("/ribbon-api")
public class RibbonApiController {
    @Autowired
    private LoadBalancerClient loadBalancerClient;

    /**
     * 获取ribbon获取服务的服务地址
     * @author alan
     * @date 2020/9/13 19:44
     * @param serviceId   服务id
     * @return  java.lang.Object
     */
    @GetMapping("/choose")
    public Object chooseUrl(@RequestParam("serviceId") String serviceId) {
        return loadBalancerClient.choose(serviceId);
    }
}
